USE [GESTION2]
GO

IF EXISTS (SELECT name 
         FROM   sysobjects 
         WHERE  name = 'WASP_D0002_TRANF1_TABLE_CSOPF000'
         AND        type = 'P')
    DROP PROCEDURE [dbo].[WASP_D0002_TRANF1_TABLE_CSOPF000]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[WASP_D0002_TRANF1_TABLE_CSOPF000]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[WASP_D0002_TRANF1_TABLE_CSOPF000]

GO


CREATE PROCEDURE [dbo].[WASP_D0002_TRANF1_TABLE_CSOPF000]
AS

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[CSOPF000]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[CSOPF000]

CREATE TABLE [dbo].[CSOPF000] (
	[CRAGENCIA] [int] NULL ,
	[CRCREDITO] [int] NULL ,
	[CRMARCA] [char] (1) COLLATE Modern_Spanish_CI_AS NULL ,
	[CRRUTDEUDO] [decimal](8, 0) NULL ,
	[CRTIPCLIE] [numeric](2, 0) NULL ,
	[CRDVEDEUDO] [char] (1) COLLATE Modern_Spanish_CI_AS NULL ,
	[CRRUTCOD1] [decimal](8, 0) NULL ,
	[CRDVECOD1] [char] (1) COLLATE Modern_Spanish_CI_AS NULL ,
	[CRRUTCOD2] [decimal](8, 0) NULL ,
	[CRDVECOD2] [char] (1) COLLATE Modern_Spanish_CI_AS NULL ,
	[CRRUTEMPRE] [int] NULL ,
	[CRDVEEMPRE] [char] (1) COLLATE Modern_Spanish_CI_AS NULL ,
	[CRCLASE] [decimal](2, 0) NULL ,
	[CRCUOTAS] [decimal](2, 0) NULL ,
	[CRFECAPROB] [decimal](8, 0) NULL ,
	[CRVALCUOTA] [decimal](9, 2) NULL ,
	[CRDIASPRIM] [int] NULL ,
	[CRMONTO] [decimal](11, 2) NULL ,
	[CRORIGEN] [decimal](11, 2) NULL ,
	[CRSEGURO] [decimal](9, 2) NULL ,
	[CRTASA] [decimal](8, 4) NULL ,
	[CRESPECIAL] [char] (1) COLLATE Modern_Spanish_CI_AS NULL ,
	[CRMODIFICA] [char] (1) COLLATE Modern_Spanish_CI_AS NULL ,
	[STSMODREGC] [decimal](1, 0) NULL ,
	[FMODIFREGC] [decimal](8, 0) NULL ,
	[USRMODREGC] [char] (10) COLLATE Modern_Spanish_CI_AS NULL ,
	[CRINDICA] [char] (2) COLLATE Modern_Spanish_CI_AS NULL ,
	[CRSERIE] [decimal](4, 0) NULL ,
	[CRNOTARIO] [decimal](6, 0) NULL ,
	[CRIMPUESTO] [decimal](6, 0) NULL ,
	[CRCOMISION] [decimal](10, 0) NULL ,
	[CRFECUPAGO] [decimal] NULL ,
	[USRMODAPRO] [char] (10) COLLATE Modern_Spanish_CI_AS NULL ,
	[CRFECRELIQ] [decimal](8, 0) NULL ,
	[USRMODRELI] [char] (10) COLLATE Modern_Spanish_CI_AS NULL ,
	[CRFECPRVEN] [decimal] NULL ,
	[CRGASTOPER] [decimal](6, 0) NULL ,
	[CRMONABONA] [decimal](11, 2) NULL ,
	[CRESTADO] [char] (1) COLLATE Modern_Spanish_CI_AS NULL ,
	[CRSEGDESGR] [decimal](7, 0) NULL ,
	[CRSTSVGTE] [decimal](1, 0) NULL ,
	[CRSTSMORA] [decimal](1, 0) NULL ,
	[CRAGECOLOC] [int] NULL ,
	[FILLER] [char] (40) COLLATE Modern_Spanish_CI_AS NULL ,
	[ENDEUD_MAXIMO] [decimal](17, 2) NULL ,
	[DISPONIBLE] [decimal](17, 2) NULL ,
	[COD_ANALISTA] [char] (30) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
	[ANALISTA] [char] (30) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
	[ESTADOTRAB] [int] NULL ,
	[CRMONTO_LIQ] [numeric](11, 0) NULL ,
	[cancelado] [varchar] (2) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
	[Solicitante] [int] NULL ,
	[Tip_Cancela] [varchar] (6) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
	[CRSEGCesantia] [numeric](9, 0) NULL ,
	[CTABANTOTAL] [numeric](9, 0) NULL ,
	[Oficina] [char] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
	[Vendedor] [char] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
	[crsegsalud] [numeric](9, 0) NULL 
) ON [PRIMARY]

INSERT INTO dbo.CSOPF000 
	SELECT
		CRAGENCIA,
		CONVERT(INT,CRCREDITO),
		CONVERT(CHAR(1),CRMARCA),
		CONVERT(DECIMAL(8,0),CRRUTDEUDO),
		TIPO_CLIENTE,
		CRDVEDEUDO,
		CONVERT(DECIMAL(8,0),CRRUTCOD1),
		CRDVECOD1,
		CONVERT(DECIMAL(8,0),CRRUTCOD2),
		CRDVECOD2,
		CRRUTEMPRE,
		CRDVEEMPRE,
		CRCLASE,
		CRCUOTAS,
		CRFECAPROB,
		CRVALCUOTA,
		CRDIASPRIM,
		CRMONTO,
		CRORIGEN,
		CRSEGURO,
		CRTASA,
		CONVERT(CHAR(1),CRESPECIAL),
		CONVERT(CHAR(1),CRMODIFICA),
		STSMODREGC,
		FMODIFREGC,
		CONVERT(CHAR(10),USRMODREGC),
		CONVERT(CHAR(2),CRINDICA),
		CRSERIE,
		CRNOTARIO,
		CRIMPUESTO,
		CRCOMISION,
		CONVERT(DECIMAL(8,0),CRFECUPAGO),
		CONVERT(CHAR(10),USRMODAPRO),
		CRFECRELIQ,
		CONVERT(CHAR(10),USRMODRELI),
		CONVERT(DECIMAL(8,0),CRFECPRVEN),
		CRGASTOPER,
		CRMONABONA,
		CONVERT(CHAR(1),CRESTADO),
		CRSEGDESGR,
		CONVERT(DECIMAL(1,0),CRSTSVGTE),
		CRSTSMORA,
		CRAGECOLOC,
		CONVERT(CHAR(40),FILLER),
		ENDEUD_MAXIMO,
		DISPONIBLE,
		UBNOM,
		ANALISTA,
		ESTADOTRAB,
		MONTO_LIQ,
		CANCELADO,
		SOLICITANTE,
		TIP_CANCELA,
		CRSEGCESANTIA,
		CTABANTOTAL,
		OFICINA,
		VENDEDOR,
		segsalud
	FROM [dbo].[CSPF000_TEMP]
GO
